#pragma once

#include "Windows.h"
#include "Constants.h"
#include <vector>
#include <string>
using namespace std;

//#include "afxinet.h"

// 1. Windows API: MoveFile, CopyFile, DeleteFile, CreateFile, CreateDirectory, RemoveDirectory
// 2. SHFileoperation
// 3. Run-Time library: _tmkdir, _trmdir
class DLLEXPIMP CStream
{
public:
	static bool CreateFolder(const wchar_t* szPath);

	static bool DeleteFolder(const wchar_t* szPath);

	// Copy all source from szFrom, including the folder itself to the path under szTo
	static bool CopyFolder(const wchar_t* szFrom, const wchar_t* szTo, bool bCoverIfExists = true);

	static bool MoveFolder(const wchar_t* szFrom, const wchar_t* szTo, bool bCoverIfExists = true); 

	static bool RenameFolder(const wchar_t* szOrigion, const wchar_t* szNew, bool bCoverIfExists = true);

	//
	// XML file operation
	//
	static void FormatXML(const wchar_t* pszPath);
	static void InsertXML(const wchar_t* pszPath, const wchar_t* pszNodeName, const wchar_t* pszName, const wchar_t* pszValue, bool bNeedFormatFirst = false);

	//
	// retrive all files under the folder specified by pszFolderPath
	// return value are file structure hold file info, like create time, LastAccessTime, file name
	// the pszFolderPath shouldn't contains the last "\" character, for example:
	// "C:" 
	static bool RetriveFolderFiles(const wchar_t* pszFolderPath, std::vector<WIN32_FIND_DATA>& vecFiles);
	//static bool RetriveFolderFiles(string strFPath, std::vector<string>& vecFileName, bool bRecursive = false, string strPrefix = "");


	// Search File in give folder pathes. 
	// strFolders is separated by ";" and the last path has no ";" follows.
	//  for example: C:\Program Files\Microsoft Visual Studio 9.0\Common7;C:\Program Files\Microsoft Visual Studio 9.0\ImportProjects;C:\Program Files
	// return "" if not founded. if the file exists more than once, return the first one.
	static CString SearchFile(CString strKey, CString strFolders);

	
	static CString CreateGUID(bool bWithBrace = true);

	//
	// CString utitlities
	//
	static CString GetSegment(const CString& strSrc, const CString& strHead, const CString& strEnd);
	static bool Split(CString str, char szsplit, std::vector<CString>& vecStrs);	
	
	//
	// path utilities
	//
	static CString ExtraNameFromPath(const CString& strPath);
	static CString ExtraDirectoryPath(const CString& strPath);
	static CString ExtraDirectParent(const CString& strPath);
};

